package com.xm.servlet.background.activity;

import com.google.gson.Gson;
import com.xm.entity.Message;
import com.xm.service.background.MessageService;
import lombok.SneakyThrows;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 活动Servlet
 *
 * @author 陈盼
 * @date 2023-12-28 下午 07:10
 */
@WebServlet("/background/add/activity")
public class AddActivityServlet extends HttpServlet {
    private final MessageService service = new MessageService();

    @SneakyThrows
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String message = req.getParameter("message");
        System.out.println(new Gson().fromJson(message, Message.class));
        resp.getWriter().print(service.addMessage(new Gson().fromJson(message, Message.class)));
    }
}
